package com.jy.rhin.infra.repo.document.template.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jy.rhin.infra.repo.document.template.mapper.DocumentTemplateMapper;
import com.jy.rhin.infra.repo.document.template.po.DocumentTemplatePo;
import com.jy.rhin.sdk.dto.document.template.DocumentTemplateDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: lww
 * @Date: 2022/6/9 17:14
 */
@Service
public class DocumentTemplateQueryHandler {

    @Resource
    DocumentTemplateMapper documentTemplateMapper;

    /**
     * 查询文档模板
     *
     * @param documentType
     * @return
     */
    public List<DocumentTemplateDto> queryTemplate(String documentType) {
        QueryWrapper<DocumentTemplatePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DocumentTemplatePo::getDocumentType, documentType);
        List<DocumentTemplatePo> documentTemplatePoList = documentTemplateMapper.selectList(queryWrapper);
        return documentTemplatePoList.stream().map(documentTemplatePo -> {
            DocumentTemplateDto dto = new DocumentTemplateDto();
            BeanUtils.copyProperties(documentTemplatePo, dto);
            return dto;
        }).collect(Collectors.toList());
    }


}
